
#ifndef YAOPLAYER3_YAOREADER_H
#define YAOPLAYER3_YAOREADER_H

#include <string>

extern "C"
{
#include "libavformat/avformat.h"
#include "libavutil/avutil.h"
}

class YaoPacket;
class YaoStream;

class YaoReader {
public:
    YaoReader();
    ~YaoReader();

    int Open(std::string _path);
    int Close();
    int Read(YaoPacket * packet);
    int GetStreamIndex(enum AVMediaType type);
    int GetStream(YaoStream * stream, int streamIndex);

public:
    std::string path;
    AVFormatContext * formatContext = nullptr;
};

class YaoPacket {
public:
    YaoPacket();
    ~YaoPacket();
    int GetPktStreamIndex();
    int64_t GetPktDuration();
public:
    AVPacket * avPacket = nullptr;

};

class YaoFrame {
public:
    YaoFrame();
    ~YaoFrame();

    void VideoPrint();
    void AudioPrint();

    int GetY(unsigned char* y);
    int GetU(unsigned char* u);
    int GetV(unsigned char* v);
public:
    AVFrame * avFrame = nullptr;

};

class YaoFFmpegDecoder {
public:
    YaoFFmpegDecoder(YaoStream * stream);
    ~YaoFFmpegDecoder();
    int Open();
    int SendPacket(YaoPacket * packet);
    int ReceiveFrame(YaoFrame * frame);

public:
    AVCodecContext * avCodecContext = nullptr;
    AVCodec * avCodec = nullptr;
};

class YaoStream {
public:
    YaoStream();
    ~YaoStream();
public:
    int index = -1;
    AVCodecParameters * avCodecParameters = nullptr;
};



#endif //YAOPLAYER3_YAOREADER_H
